﻿using System;
using Cosmos.Compiler.Builder;

using Cosmos.Hardware;

namespace DragoDOS
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion

        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            Console.ForegroundColor = ConsoleColor.Red;
            
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting.");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting..");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting...");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting.");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting..");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting...");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting.");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting..");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting...");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting.");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Booting..");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Booting...");
                Console.Beep(500, 18000);
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("DragoDOS version 1.0 booted successfully");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Login COMMAND input:");
                Console.ReadLine();
            

            if (Cosmos.Hardware.Keyboard.AltPressed == true)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("USERNAME:");
                Console.ForegroundColor = ConsoleColor.Yellow;
                string user = Console.ReadLine(); 
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("PASSWORD:");
                Console.ForegroundColor = ConsoleColor.Black;
                string password = Console.ReadLine();
                if (user == "Drago")
                {
                    if (password == "dospassword")
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Clear();
                        Console.WriteLine("DragoDOS version 1.0 Logged in succesfully successfully");
                        while (true)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("DRAGON-PROMPT>>");
                            Console.ForegroundColor = ConsoleColor.Yellow;
                           string prompt = Console.ReadLine();
                            prompt = prompt.ToLower();
                           if (prompt == "cls")
                           {
                               Console.Clear();
                           }
                           else if (prompt == "help" || prompt == "command" || prompt == "?")
                           {
                               Console.WriteLine("[CLS]\t\tClears Screen");
                               Console.WriteLine("[SHUTDOWN]\t\tShutdown DragoDOS");
                               Console.WriteLine("[REBOOT]\t\tRestarts DragoDOS");
                               Console.WriteLine("[DISPLAYS]\t\tEchoes entered text");
                               Console.WriteLine("[CALC]\t\tA simple calc program");
                           }
                           else if (prompt.StartsWith("display"))
                           {
                               prompt.Replace("display ", "");
                               Console.ForegroundColor = ConsoleColor.Red;
                               Console.WriteLine(prompt);
                           }
                           else if (prompt == "shutdown")
                           {
                               Cosmos.Sys.Deboot.ShutDown();
                           }
                           else if (prompt == "reboot")
                           {
                               reb();
                           }
                           else if (prompt == "calc")
                           {
                               int s = 0;
                               int e = 1000;
                               int Num1 = ReadNum(s, e);
                               int Num2 = ReadNum(s, e);
                               Console.ForegroundColor = ConsoleColor.Red;
                               Console.Write("[+|-|*|/]:");
                               Console.ForegroundColor = ConsoleColor.Yellow;
                               char b = char.Parse(Console.ReadLine());
                               Console.ForegroundColor = ConsoleColor.Yellow; ;
                               int result = 0;
                               switch (b)
                               {
                                   case '+':
                                       result =  Num1+Num2;
                                       Console.WriteLine(result.ToString());
                                       break;
                                   case '-':
                                       result = Num1 - Num2;
                                       Console.WriteLine(result.ToString());
                                       break;
                                   case '*':
                                       result = Num1 * Num2;
                                       Console.WriteLine(result.ToString());
                                       break;
                                   case '/':
                                       result = Num1 / Num2;
                                       Console.WriteLine(result.ToString());
                                       break;

                               }

                           }
                           else
                           {
                               Console.ForegroundColor = ConsoleColor.Red;
                               Console.WriteLine("Unrecogonized COMMAND. Please type '?' for more help");
                           }

                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Error. Unrecogonized PASSWORD. System rebooting.....");
                        Console.Beep(500, 18000);
                        Cosmos.Sys.Deboot.Reboot();
                    }
                }
                else
                {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error. Unrecogonized USERNAME. System rebooting.....");
                Console.Beep(500, 18000);
                Cosmos.Sys.Deboot.Reboot();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error. Unrecogonized login command. System rebooting.....");
                Cosmos.Sys.Deboot.Reboot();
            }
            while (true)
                ;
        }
        public static void vga()
        {
            VGAScreen.SetMode320x200x8();
            VGAScreen.SetPaletteEntry(0,63,0,0);
            VGAScreen.SetPixel(30, 40, 1);
            VGAScreen.Clear(0);
        }
        public static int ReadNum(int start, int end)
        {
            int c;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("Enter NUM:");
            Console.ForegroundColor = ConsoleColor.Yellow;
            string ui = Console.ReadLine();
            

            for (c = start; c <= end; c++)
            {
                if (c.ToString() == ui)
                {
                    return c;
                }
            }
            return 0;
        }
        public static void reb()
        {
            vga();
            Console.Beep(3000,36000);
            Cosmos.Sys.Deboot.Reboot();
        }
    }
}